package logic

import (
	"context"
	"errors"
	"regi-med/model/mysql"

	"regi-med/regirpc/internal/svc"
	"regi-med/regirpc/regirpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegiShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRegiShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegiShowLogic {
	return &RegiShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *RegiShowLogic) RegiShow(in *regirpc.RegiShowRequest) (*regirpc.RegiShowResponse, error) {
	// todo: add your logic here and delete this line

	var regi mysql.Regi

	if err := regi.RegiShow(mysql.DB, in.RegiId); err != nil {
		return nil, errors.New("当前挂号不存在")
	}

	return &regirpc.RegiShowResponse{
		RegiId:     int64(in.RegiId),
		Name:       regi.Name,
		StatusCard: regi.StatusCard,
		WeiXiName:  regi.WeiXiName,
		Area:       regi.Area,
		RegiCode:   regi.RegiCode,
		CardCode:   regi.CardCode,
		PhoneCode:  regi.PhoneCode,
		Image:      regi.Image,
		Ties:       regi.Ties,
	}, nil
}
